package dao.proxy.comm;

import java.util.List;

import dao.comm.IHomeworkDAO;
import dao.impl.comm.HomeworkDAOImpl;
import dbc.comm.DatabaseConnection;
import vo.comm.Homework;

public class HomeworkDAOProxy implements IHomeworkDAO{
	private DatabaseConnection dbc=null;
	private IHomeworkDAO dao=null;
	public HomeworkDAOProxy() throws Exception{
		this.dbc=new DatabaseConnection();
		this.dao=new HomeworkDAOImpl(this.dbc.getConnection());
	}
	public boolean doCreate(Homework homework) throws Exception{
		boolean flag=false;
		if(this.dao.findByName(homework.getHomeworkname())==null){
			flag=this.dao.doCreate(homework);
		}
		this.dbc.close();
		return flag;
	}
	public boolean doDelete(Homework homework) throws Exception{
		boolean flag=false;
		flag=this.dao.doDelete(homework);
		this.dbc.close();
		return flag;
	}
	public Homework findByName(String homeworkname) throws Exception{
		Homework homework=null;
		homework=this.dao.findByName(homeworkname);
		this.dbc.close();
		return homework;
	}
	public List<Homework> findAll(String keyWord) throws Exception{
		List<Homework> all=null;
		all=this.dao.findAll(keyWord);
		this.dbc.close();
		return all;
	}
	public boolean doUpdate(Homework homework) throws Exception{
		boolean flag=false;
		flag=this.dao.doUpdate(homework);
		this.dbc.close();
		return flag;
	}
	public boolean doPublish(Homework homework) throws Exception{
		boolean flag=false;
		flag=this.dao.doPublish(homework);
		this.dbc.close();
		return flag;
	}
	public List<Homework> findPublish(String keyWord) throws Exception{
		List<Homework> all=null;
		all=this.dao.findPublish(keyWord);
		this.dbc.close();
		return all;
	}
	public boolean doUpload(Homework homework) throws Exception{
		boolean flag=false;
		flag=this.dao.doUpload(homework);
		this.dbc.close();
		return flag;
	}
	public List<Homework> findUpload(String keyWord) throws Exception{
		List<Homework> all=null;
		all=this.dao.findUpload(keyWord);
		this.dbc.close();
		return all;
	}
	public boolean checkUpload(Homework homework) throws Exception{
		boolean flag=false;
		flag=this.dao.checkUpload(homework);
		this.dbc.close();
		return flag;
	}
	public boolean doScore(Homework homework) throws Exception{
		boolean flag=false;
			flag=this.dao.doScore(homework);
		this.dbc.close();
		return flag;
	}
	public List<Homework> findScore(String keyWord1,String keyWord2) throws Exception{
		List<Homework> all=null;
		all=this.dao.findScore(keyWord1,keyWord2);
		this.dbc.close();
		return all;
	}
	public boolean findAvg(Homework homework)throws Exception{
		boolean flag=false;
		flag=this.dao.findAvg(homework);
		this.dbc.close();
		return flag;
	}
}
